<template src="./template.html"></template>

<style src="./style.css" scoped></style>
<script>
    import securityBg from "../assets/images/top-bg.png";
    import signSuccessIcon from "../assets/images/signed-icon.png";

    import api from "api/api";
    import modal from "utils/modal";
    import navigator from "utils/navigator";
    import notification from "utils/notification";
    import constant from "constants/constant";

    export default{
        data(){
            return {
                securityBg: securityBg,
                signSuccessIcon: signSuccessIcon,
                pageLoaded: false, //页面加载成功标识
                signType: null, //签约类型
                title: '', //签约标题
                payWayImg: null //免密支付图片说明
            }
        },
        created() {
            let config = weex.config;
            if(typeof config.signType === 'undefined') {
                modal.toast('未知的签约类型!');
                return false;
            }
            this.signType = config.signType;
            this.getSignInfo();
        },
        methods: {
             /**
             * @description 查询签约免密支付信息函数
             */
            getSignInfo(){
                let self = this;
                api.sendHttp("getSecuritySignedApi",{signtype: self.signType}).then(res=>{
                    self.pageLoaded = true;
                    let data = res.data || {};
                    self.payWayImg = data.img;
                    self.title = data.title || '';
                },res=>{
                    self.pageLoaded = true;
                    modal.toast(res.msg);
                });
            },

             /**
             * @description 关闭免密支付签约
             */
            closeNPWDSign(){
                let self = this;
                modal.confirm({message: '您是否关闭'+this.title}).then(() => {
                    api.sendHttp("cancelSecuritySignApi",{signtype: self.signType}).then(res=>{
                        modal.toast('关闭' + self.title + '服务成功！');
                        navigator.pop();
                        notification.send(constant.EVENT_SECURITY_RELOAD,null);
                    },res=>{
                        modal.toast(res.msg || "解除签约失败");
                    });
                });
            }
        }
    }
</script>
